package com.ssyt.cdp.common;

import java.util.List;

/**
 * 分页模型
 * 
 * @author Administrator
 *
 */
public class PageModel<T> {

	// 结果集
	private List<T> list;

	// 记录数
	private long totalRecords;

	// 每页多少条数据
	private int pageSize;

	// 第几页
	private int pageNo;

	public PageModel() {
		super();
	}

	public PageModel(List<T> list, long totalRecords, int pageNo, int pageSize) {
		super();
		this.list = list;
		this.totalRecords = totalRecords;
		this.pageNo = pageNo;
		this.pageSize = pageSize;
	}

	/**
	 * 一共有多少页
	 * 
	 * @return
	 */
	public int getTotalPages() {
		return (int) Math.ceil((double) totalRecords / pageSize);
	}

	/**
	 * 首页
	 * 
	 * @return
	 */
	public int getFirst() {
		return Constants.FIRST_PAGE;
	}

	/**
	 * 尾页
	 * 
	 * @return
	 */
	public int getLast() {
		return getTotalPages();
	}

	/**
	 * 上一页
	 * 
	 * @return
	 */
	public int getPre() {
		if (pageNo == Constants.FIRST_PAGE) {
			return Constants.FIRST_PAGE;
		}
		return pageNo - 1;
	}

	/**
	 * 下一页
	 * 
	 * @return
	 */
	public int getNext() {
		if (pageNo == getLast()) {
			return pageNo;
		}
		return pageNo + 1;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public long getTotalRecords() {
		return totalRecords;
	}

	public void setTotalRecords(long totalRecords) {
		this.totalRecords = totalRecords;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

}
